package com.ruoyi.web.controller.storage;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import com.ruoyi.storage.fitting.domain.Fitting;
import com.ruoyi.storage.fitting.service.IFittingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 配件配置Controller
 * 
 * @author zzx
 * @date 2024-05-10
 */
@RestController
@RequestMapping("/storage/fitting")
@RequiredArgsConstructor
public class FittingController extends BaseController
{
    private final IFittingService fittingService;

    /**
     * 查询配件配置列表
     */
    @PreAuthorize("@ss.hasPermi('storage:fitting:list')")
    @GetMapping("/list")
    public TableDataInfo list(Fitting fitting)
    {
        startPage();
        List<Fitting> list = fittingService.selectFittingList(fitting);
        return getDataTable(list);
    }

    /**
     * 导出配件配置列表
     */
    @PreAuthorize("@ss.hasPermi('storage:fitting:export')")
    @Log(title = "配件配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Fitting fitting)
    {
        List<Fitting> list = fittingService.selectFittingList(fitting);
        ExcelUtil<Fitting> util = new ExcelUtil<Fitting>(Fitting.class);
        util.exportExcel(response, list, "配件配置数据");
    }

    /**
     * 获取配件配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('storage:fitting:query')")
    @GetMapping(value = "/{fittingId}")
    public AjaxResult getInfo(@PathVariable("fittingId") Long fittingId)
    {
        return success(fittingService.selectFittingByFittingId(fittingId));
    }

    /**
     * 新增配件配置
     */
    @PreAuthorize("@ss.hasPermi('storage:fitting:add')")
    @Log(title = "配件配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Fitting fitting)
    {
        return toAjax(fittingService.insertFitting(fitting));
    }

    /**
     * 修改配件配置
     */
    @PreAuthorize("@ss.hasPermi('storage:fitting:edit')")
    @Log(title = "配件配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Fitting fitting)
    {
        return toAjax(fittingService.updateFitting(fitting));
    }

    /**
     * 删除配件配置
     */
    @PreAuthorize("@ss.hasPermi('storage:fitting:remove')")
    @Log(title = "配件配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fittingIds}")
    public AjaxResult remove(@PathVariable Long[] fittingIds)
    {
        return toAjax(fittingService.deleteFittingByFittingIds(fittingIds));
    }

    @GetMapping("/selectListFitting")
    public TableDataInfo listSelect(String keyWord)
    {
        startPage();
        List<Fitting> list = fittingService.selectFittingListByFittingName(keyWord);
        return getDataTable(list);
    }
}
